﻿using System;
using System.Windows;
using System.Windows.Data;

namespace AsyncTaskManager.Converter
{
    public class NullToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool flag = value != null;
            if (value is string && string.IsNullOrEmpty((string)value))
                flag = false;
            if (value is int && (int)value == 0)
                flag = false;

            if (parameter != null && bool.Parse(parameter.ToString())) // le paramètre correspond à la négation du test
                return (flag ? Visibility.Collapsed : Visibility.Visible);
            return (flag ? Visibility.Visible : Visibility.Collapsed);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
